
// 通知文字轮播
$(function () {
  var height = $('.new-carousel-item:last').height()
  var length = $('.new-carousel-item').length
  var index = 1
  var i = 0
  setInterval(function () {
    if (index >= length) {
      index = 0
      i = 0
    }
    $('.new-carousel-div').animate({ top: (i - index) * height }, 200)
    index++
  }, 2000)
})
// 通知文字轮播结束
// 中间轮播图开始
var mySwiper = new Swiper('.swiper-container', {
  direction: 'horizontal', // 垂直切换选项
  loop: true, // 循环模式选项

  // // 如果需要分页器
  pagination: {
    el: '.swiper-pagination'
  },

  // 如果需要前进后退按钮
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev'
  },
  autoplay: true

})
// 轮播图结束
// 回到顶部

$(document).ready(function () {
  $('#qushangnmian').click(function () {
    $('html,body').animate({scrollTop: 0}, 'slow')
  })
})
// 商品几个商品的Ajax请求
var pageSize = 12
var current = 1
var arr = null
var data
$.ajax({
  url: 'https://www.ymatou.com/guess/api/getGuessLikeProducts',
  data: {
    callback: 'jQuery11240008231846451939528_1635749214565',
    pageIndex: 1,
    pageSize: pageSize,
    _: +new Date()
  },
  dataType: 'jsonp',
  success: res => {
    // console.log(res)
    arr = res.result.Products
    // console.log(arr, 33333)
    var str = ''
    for (var current = 1; current < arr.length; current+4) {
      data = arr.splice((current - 1), 4)
      // console.log(data, 222)
      // var str = ''
      data.forEach(item => {
        str += `
      <li class="item">
      <a class="pro-img">
          <img src="${item.MainPic}" alt="">
      </a>
      <a class="pro-name">
          <p>${item.Title}</p>
      </a>
      <p class="price">
          <span>￥</span>
          58
      </p>
      <p class="contion">
          <img src="./images/Japan.png" alt="">
          <span>日本</span>
      </p>
      `
      })
      // current += 4
      $('.global-body .one .shangpin>ul').html(str)
      // $('.global-body .two .shangpin>ul').html(str)
    }
  }
})

// 登录注册模块
// 如果在本地里没有名字
fn()
function fn() {
      // 在本地里获取名字
  var name = window.localStorage.getItem('name')
  if (!name) {
    $('.page-top>.container>.top-fr>div').html(`
    <a href="./login.html "><span >登录</span></a>
    <a href="./register.html"><span>注册</span></a>
    `)
  } 
    else{
    // name存在
    $('.page-top>.container>.top-fr').css('position','relative')
    $('.page-top>.container>.top-fr>div').html(`<a href="../login.html" class="info"><span>${name}</span><span></span>
      <ul><li onclick="logout()" >退出登录</li>
          <li>修改密码</li>
          <li>我的订单</li></ul>
       </a>`).css({ 'position': 'absolute','left':'-82px','z-index': '5'})
  }
}
// 退出登录
function logout() {
       fn()
    // 移除本地的数据
    window.localStorage.removeItem('name')
  window.localStorage.removeItem('userInfo')
  window.localStorage.removeItem('data')
  
  
}
$('.dengdeng').on('click', function () {
    localStorage.setItem('url', location.href)
})
